package de.kardass.jsmatep.in.reader;

import de.kardass.jsmatep.schema.jSmaTePImportConfig.FieldType;
import de.kardass.jsmatep.schema.jSmaTePImportConfig.RecordImportConfigType;

public class VariableLengthRecordReader extends AbstractRecordReader {

	public VariableLengthRecordReader(RecordImportConfigType importConfig) {
		super(importConfig);
	}

	public String readField(FieldType fieldConfig, String record) {
		String result = null;
		final int beginIdx = fieldConfig.getPosition();
		if (beginIdx < record.length()) {
			int endIdx = fieldConfig.getPosition() + fieldConfig.getLength();
			if (endIdx > record.length()) {
				endIdx = record.length();
			}
			result = record.substring(beginIdx, endIdx);
		}
		return result;
	}

}
